<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>事件通知</title>
    
	<%@ include file="../include/common.jsp"%>
	<%@ include file="../include/jbox.jsp"%>
	<%@ include file="../include/table.jsp"%>
	<%@ include file="../include/tree.jsp"%>
	<%@ include file="../include/tooltip.jsp"%>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/calendar/zh_CN_WdatePicker.js"></script>
	<style type="text/css">
		.ztree {border: 1px solid #617775;background: #f0f6e4;overflow-y:scroll;overflow-x:auto;}
		.eventlevel2 {background-position-x:left;}
		.eventlevel3 {background-position-x:left;}
		.eventlevel4 {background-position-x:left;}
		.eventlevel5 {background-position-x:left;}
		.notifymode1 {background-position-x:left;}
		.notifymode2 {background-position-x:left;}
	</style>
	<script type="text/javascript">
	//初始设定
	var map  = new Array();
	var eventTypeId = -1;
	function datagrid(){
		var oTable=	$('#depmtList').dataTable();
		//oTable.fnPageChange("first",true);
		oTable._fnAjaxUpdate();
	}
	refreshResSearch=function(resId,resName){
		if(resName == ''){
			$("#resDiv").css({"display":"none"});
		}else{
			$("#resDiv").css({"display":""});
		}
		$("#resSearch").html(resName);
		$("#resId").val(resId);
	}
	refreshTable=function(scope,scopeName){
		if(scopeName == ''){
			$("#dimensionDiv").css({"display":"none"});
		}else{
			$("#dimensionDiv").css({"display":""});
		}
		$("#dimensionSearch").html(scopeName);
		$("#dimension").val(scope);
	}
	function delDiv(id){
		window.parent.delDiv(id);
	}
	function delResDiv(id){
		window.parent.delResDiv(id);
	}
	function closeIt(){
		$(document).trigger('hideCluetip');
	}	
	$(function(){
		if('${flag}' == 0){
			$('#beginDate').val('${beginDate}');
			$('#endDate').val('${endDate}');
			
			if(parent.document.getElementById("resName").value == ''){
				$("#resDiv").css({"display":"none"});
			}else{
				$("#resDiv").css({"display":""});
			}
			$("#resSearch").html(parent.document.getElementById("resName").value);
			$("#resId").val(parent.document.getElementById("resId").value);
			
			if(parent.document.getElementById("scopeName").value == ''){
				$("#dimensionDiv").css({"display":"none"});
			}else{
				$("#dimensionDiv").css({"display":""});
			}
			$("#dimensionSearch").html(parent.document.getElementById("scopeName").value);
			$("#dimension").val(parent.document.getElementById("scope").value);
		}else{
			if('${mode}' == 2){
				$("#mode1").attr("checked", false);
			}else{
				$("#mode2").attr("checked", false);
			}
			if('${beginDate}' != ''){
				$('#beginDate').val('${beginDate}');
			}
			$("#searchFormStyle").css({"display":"none"});
		}
		//加载grid
		var oTable=	$('#depmtList').dataTable({
			"bProcessing": true, 
			"bServerSide": true,
			"sServerMethod": 'POST',
			"sAjaxSource":'${pageContext.request.contextPath}/event/notify-his!list.action?scope='+'${scope}'+'&treeId='+'${treeId}',
			"bPaginate": true,
			"bSort": true,
			"bFilter":false,
			"bJQueryUI":false,
			"sPaginationType": "full_numbers",
			"sDom":'rt <"bottom"flpi>',
			"aLengthMenu": [[10, 20, 50, 100], [10, 20, 50,100]],
			"aoColumns":[
				{"mDataProp":"user","bSortable": false},
				{"mDataProp":"mode_name","bSortable": false,
					"fnCreatedCell" : function(nTd, sData,oData, iRow,iCol) {
						var modeName = oData.mode_name;
						var ss = "<a>"+ modeName +"</a>";
						$(nTd).html(ss);
				}},
				{"mDataProp":"time"},
				{"mDataProp":"msg","bSortable": false},
				{"mDataProp":"res_name","bSortable": false},
				{"mDataProp":"event_time","bSortable": false},
				{"mDataProp":"event_status","bSortable": false,
					"fnCreatedCell" : function(nTd, sData,oData, iRow,iCol) {
						var statusName = oData.event_status;
						var ss = "<a>"+ statusName +"</a>";
						$(nTd).html(ss);
				}},
				{"mDataProp":"event_level","bSortable": false,
					"fnCreatedCell" : function(nTd, sData,oData, iRow,iCol) {
						var levelName = oData.event_level;
						var ss = "<a>"+ levelName +"</a>";
						$(nTd).html(ss);
				}},
				{"mDataProp":"id","bVisible":false}
			], 
			 "oLanguage": { 
			 				"sLengthMenu": "每页 _MENU_ 条",
			 		 		"sZeroRecords": "  ",
							"sInfo": "当前从 _START_ 到 _END_ 条,共 _TOTAL_ 条记录", 
							"sInfoEmpty": "没有找到记录",
							"oPaginate":{"sFirst":"首页","sPrevious":"上一页","sNext":"下一页","sLast":"尾页"}	
			},
		    "fnServerParams":function(aoData){
		    	//级别
		    	var str=document.getElementsByName("level");
		    	var objarray=str.length;
		    	var level = new Array();
		    	var j = 0;
		    	for (i=0;i<objarray;i++)
		    	{
		    	  if(str[i].checked == true)
		    	  {
		    		  level[j++]=(str[i].value);
		    	  }
		    	}
		    	if(level !='')
		    	{
		    		aoData.push({'name':'level','value':level});
		    	}
		    	//通知方式
		    	var str=document.getElementsByName("mode");
		    	var objarray=str.length;
		    	var mode = new Array();
		    	var j = 0;
		    	for (i=0;i<objarray;i++)
		    	{
		    	  if(str[i].checked == true)
		    	  {
		    		  mode[j++]=(str[i].value);
		    	  }
		    	}
		    	if(mode !='')
		    	{
		    		aoData.push({'name':'mode','value':mode});
		    	}
		    	//时间
		    	var beginDate = $('#beginDate').val();
		    	if(beginDate!='')
		    	{
		    		aoData.push({'name':'beginDate','value':beginDate});
		    	}
		    	var endDate = $('#endDate').val();
		    	if(endDate!='')
		    	{
		    		aoData.push({'name':'endDate','value':endDate});
		    	}
		    	//维度范围
		    	if('$("#dimension").val()' != ''){
		    		aoData.push({'name':'dimension','value':$("#dimension").val()});
		    	}
		    	//通知人
		    	if('$("#userId").val()' != ''){
		    		aoData.push({'name':'userId','value':$("#userId").val()});
		    	}
		    	//资源ID范围
		    	if('$("#resId").val()' != ''){
		    		aoData.push({'name':'resId','value':$("#resId").val()});
		    	}
		    },
		    "fnRowCallback":function( nRow, aData, iDisplayIndex, iDisplayIndexFull )
			{		
			},
			 "fnDrawCallback": function () {
		    }
	});

	
	});
	//得到当前选中的
	function fnGetSelected() {   
		var selections = $('#depmtList tr.row_selected');
		return selections;
	} 
	
	function search(){
		var oTable=	$('#depmtList').dataTable();
		oTable.fnPageChange("first",true);
	}
	
	function notifyExport(){
		var str=document.getElementsByName("level");
    	var objarray=str.length;
    	var level = new Array();
    	var j = 0;
    	for (i=0;i<objarray;i++)
    	{
    	  if(str[i].checked == true)
    	  {
    		  level[j++]=(str[i].value);
    	  }
    	}
    	//通知方式
    	var str=document.getElementsByName("mode");
    	var objarray=str.length;
    	var mode = new Array();
    	var j = 0;
    	for (i=0;i<objarray;i++)
    	{
    	  if(str[i].checked == true)
    	  {
    		  mode[j++]=(str[i].value);
    	  }
    	}
    	var beginDate = $('#beginDate').val();
    	var endDate = $('#endDate').val();
    	//通知人
    	var userId = $("#userId").val();
		window.location="${pageContext.request.contextPath}/event/notify-export!doExport.action?level="+level+"&beginDate="+beginDate+"&endDate="+endDate+"&mode="+mode+"&dimension="+$("#dimension").val()+"&userId="+userId+"&resId="+$("#resId").val();
	}
	
	function view(id){
		var opt = { title: "查看事件通知",width:480,height:360,buttons: {}};
		if('${flag}' == 0){
			var url ="iframe:event/notify-his!view.action?id="+id;
			getTopWin(window).openjBox(url,opt,'event-view-main',window);
		}else{
			var url ="iframe:../event/notify-his!view.action?id="+id;
			$.jBox(url, opt);
		}
	}
	
	var setting = {
			check: {
				enable: true,
				chkboxType: {"Y" : "ps", "N" : "ps"}
			},
			view: {
				dblClickExpand: false
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				onCheck: onCheck
			}
		};
		function onCheck(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			nodes = zTree.getCheckedNodes(true),
			v = "";
			m = "";
			for (var i=0, l=nodes.length; i<l; i++) {
				//过滤出部门
				if(!(nodes[i].id.indexOf(',') > 0)){
					v += nodes[i].name + ",";
					m += nodes[i].id + ",";
				}
			}
			if (v.length > 0 ) v = v.substring(0, v.length-1);
			if (m.length > 0 ) m = m.substring(0, m.length-1);
			$("#user").val(v);
			$("#userId").val(m);
		}
		function showMenu() {
			$.ajax({ 
				  type:"post", 
				  url:"${pageContext.request.contextPath}/event/notify-his!userTreeData.action?userId="+$('#userId').val(), 
				  data:"&eventTypeId="+eventTypeId, 
				  datatype:"json",
				  success:function(data) { 
						var zNodes=eval(data);
						$.fn.zTree.init($("#treeDemo"), setting, zNodes);
							var obj = $("#user");
							var offset = $("#user").offset();
							$("#menuContent").css({left:offset.left + "px", top:offset.top + obj.outerHeight() + "px"}).slideDown("fast");
							$("body").bind("mousedown", onBodyDown);
				  } 
		     	})
		}
		function hideMenu() {
			$("#menuContent").fadeOut("fast");
			$("body").unbind("mousedown", onBodyDown);
		}
		function onBodyDown(event) {
			if (!(event.target.id == "menuBtn" || event.target.id == "user" || $(event.target).parents("#menuContent").length>0)) {
				hideMenu();
			}
		}
	</script>
  </head>
  
  <body>
  	<div id="menuContent" style="display:none; position: absolute;z-index:100;">
		<ul id="treeDemo" class="ztree" style="margin-top:0; width:220px; height: 300px;"></ul>
	</div>
  	<div class="searchFormStyle" id="searchFormStyle">
  		<div id="resDiv" style="display: none;">
  			<label>资源名称：</label>
			<span id="resSearch" style="float: left;"></span>
			<input type="hidden" id="resId" name="resId"/>
  		</div>
  		<div id="dimensionDiv" style="display: none;">
  			<label>资源类别：</label>
			<span id="dimensionSearch"></span>
			<input type="hidden" id="dimension" name="dimension"/>
  		</div>
  		<div>
  			<label>事件级别：</label>
			<input type="checkbox" name="level" id="level1" value="2" checked="checked"><label class="eventlevel2" style="padding-left: 20px;width: 30px;">轻微</label>
			<input type="checkbox" name="level" id="level2" value="3" checked="checked"><label class="eventlevel3" style="padding-left: 20px;width: 30px;">警告</label>
			<input type="checkbox" name="level" id="level3" value="4" checked="checked"><label class="eventlevel4" style="padding-left: 20px;width: 30px;">重要</label>
			<input type="checkbox" name="level" id="level4" value="5" checked="checked"><label class="eventlevel5" style="padding-left: 20px;width: 30px;">严重</label>
  			<label>&nbsp;&nbsp;通知方式：</label>
			<input type="checkbox" name="mode" id="mode1" value="1" checked="checked"><label class="notifymode1" style="padding-left: 20px;width: 30px;">短信</label>
			<input type="checkbox" name="mode" id="mode2" value="2" checked="checked"><label class="notifymode2" style="padding-left: 20px;width: 30px;">邮件</label>
  			
  		</div>
  		<div>
  	    	<label>&nbsp;&nbsp;通知人：</label>
			<input id="user" type="text" name="user" readonly value="" style="width:225px;" onclick="showMenu();" />
			<input id="userId" type="hidden" name="userId"/>
			<label>通知时间：</label>
			<input id="beginDate" name="beginDate" class="Wdate" type="text" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',maxDate:'%y-%M-%d %H:%m'})"/>
			<label>-</label>
			<input id="endDate" name="endDate" class="Wdate" type="text" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',minDate:$('#beginDate').val()})"/>
			<input type="button" onclick="search();" value="查询" class="searchFormButtonStyle">
  		</div>
	</div>
	<h2 class="title-h2"><span><img src="${pageContext.request.contextPath}/style/default/bsm/images/arrow-down.gif"/></span>通知列表</h2>
	<div class="toolbar">
 		<a class="page_excel" href="javascript:notifyExport();">导出</a>
	</div>
	<div>
	<table id="depmtList" width="100%" cellpadding="0" cellspacing="0" border="0" class="display">
		<thead>
			<tr>
				<th width="60">通知人</th>
				<th width="40">通知方式</th>
				<th width="120">通知时间</th>
				<th>通知内容</th>
				<th width="140">资源名称</th>
				<th width="120">产生时间</th>
				<th width="60">事件状态</th>
				<th width="60">事件级别</th>
			</tr>
		</thead>
	</table>
	</div>
  </body>
</html>